package com.cyjt.operation.ui;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.cyjt.operation.R;
import com.cyjt.operation.adapter.ShiftRecordAdapter;
import com.cyjt.operation.bean.InspectionTimeInfo;
import com.cyjt.operation.bean.ShiftRecord;
import com.cyjt.operation.view.ActionBarLayout;

/**
 * 排班记录查询的Activity
 * 
 * @author LTP
 * 
 */
public class QueryShiftRecordActivity extends Activity {
	/** 排班记录列表 */
	private ListView listView_query_shift_record;
	private List<ShiftRecord> shiftRecordList = new ArrayList<ShiftRecord>();
	private List<InspectionTimeInfo> inspectionTimeInfo;

	private TextView query_endtime_txt, query_starttime_txt,
			query_areaname_txt;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_query_shift_record);
		initView();
		initListView();
		inspectionTimeInfo = (List<InspectionTimeInfo>) getIntent()
				.getSerializableExtra("inspectionTimeInfo");
		for (int i = 0; i < inspectionTimeInfo.size(); i++) {

			query_endtime_txt.setText(getSubString(inspectionTimeInfo.get(0)
					.getEndAtString().toString())
					+ "");
			query_starttime_txt.setText(getSubString(inspectionTimeInfo.get(0)
					.getStartAtString().toString())
					+ "");
			query_areaname_txt.setText(inspectionTimeInfo.get(0).getTitle()
					.toString()
					+ "");
		}
	}
	/**
	 * 改时间类型
	 * @param date
	 * @return
	 */
	private String getSubString(String date) {
		String a = date.substring(0, 10);
		if ("1970-01-01".equals(a)) {
			return date.substring(11, 19).toString();
		}
		return "";
	}

	/** 控件初始化 */
	private void initView() {
		ActionBarLayout.setTitle("排班记录查询");
		query_endtime_txt = (TextView) findViewById(R.id.query_endtime_txt);
		query_starttime_txt = (TextView) findViewById(R.id.query_starttime_txt);
		query_areaname_txt = (TextView) findViewById(R.id.query_areaname_txt);

	}

	/** 初始化排班列表数据 */
	private void initShiftRecord() {
		for (int i = 1; i < 100; i++) {
			ShiftRecord shiftRecord = new ShiftRecord();
			// ShiftRecord shiftRecord = new ShiftRecord(i, "路段" + i, "2015-6-2"
			// + i, "王" + i, "code" + i);
			shiftRecord.setId(i);
			shiftRecord.setAreaId("环湖东路");
			shiftRecord.setDuringtime("2015-6-10");
			shiftRecord.setName("老王");
			shiftRecord.setCode(i + "");
			shiftRecordList.add(shiftRecord);
		}
	}

	/** ListView的初始化 */
	private void initListView() {
		if (shiftRecordList != null || shiftRecordList.size() > 0) {
			ShiftRecordAdapter adapter = new ShiftRecordAdapter(this,
					R.layout.list_view_item_for_shift_record, shiftRecordList);
			listView_query_shift_record = (ListView) findViewById(R.id.listView_query_shift_record);
			listView_query_shift_record.setAdapter(adapter);
		} else {
			Toast.makeText(this, "排版记录查询为空", Toast.LENGTH_SHORT).show();
		}

	}
}
